<template>
  <div class="sbody">
    <headMain :mensid="mensid" />
    <!-- 考核列表 -->
    <div class="tplistbox">
      <div class="bjbox">
        <img src="@/assets/images/bjt.png" alt="" />
      </div>
      <div class="ztnr">
        <div class="tpinputbox">
          <a-input
            class="tpinputzd"
            v-model="formModel.examineName"
            placeholder="请输入图谱名称"
            allow-clear
          />
          <div class="tpbutton" @click="onPageChange(1)">搜索</div>
          <div class="tpbutton tpbuttonnthchild" @click="reset">重置</div>
        </div>
        <div class="tpmainbox">
          <a-table
            row-key="userId"
            :loading="loading"
            page-position="bottom"
            :stripe="true"
            :pagination="pagination"
            :columns="columns"
            :data="datas"
            :bordered="{ cell: true }"
            @page-change="onPageChange"
            @page-size-change="onPageSizeChange"
          >
            <!-- examineStatus -->
            <template #examineStatus="{ record }">
              <div
                :class="
                  record.examineStatus == 1
                    ? 'khztbox'
                    : record.examineStatus == 2
                    ? 'khztboxs'
                    : record.examineStatus == 1
                    ? 'khztboxss'
                    : 'khztboxss'
                "
                >{{
                  record.examineStatus == 1
                    ? '考核中'
                    : record.examineStatus == 2
                    ? '已结束'
                    : record.examineStatus == 1
                    ? '已放弃'
                    : '空状态'
                }}</div
              >
            </template>
            <template #xq="{ record }">
              <div class="xqbox" @click="xqfn(record)">详情</div>
            </template>
          </a-table>
        </div>
      </div>
    </div>
    <!-- 选择考核试题 -->
    <div class="tcbox" v-if="ksshow">
      <div class="tctopbox">
        <div class="tctopname">考核详细信息</div>
        <div class="tcclose" @click="ksshow = false"
          ><icon-close :size="25"
        /></div>
      </div>
      <div class="tcmainbox">
        <div class="tcmainitem">
          <div class="tcitemname">选择图谱</div>
          <div class="tcitdes">
            <a-select
              :options="options"
              placeholder="请选择图谱"
              :field-names="fieldNames"
              :style="{ width: '100%', height: '100%' }"
              @change="changefn"
              v-model="medicineAtlasId"
            />
          </div>
        </div>
      </div>
      <div class="tsred" v-if="tipshow">请先选择图谱才能查看详情</div>
      <div class="startbox" @click="gostart">查看详情</div>
    </div>
    <div class="zzcbox" v-if="ksshow"></div>
  </div>
</template>

<script lang="ts" setup>
  import { computed, ref, reactive } from 'vue';
  import { Message, Modal } from '@arco-design/web-vue';
  import headMain from '@/views/headmain/index.vue';
  import { khList, getrecordlist, getTp } from '@/api/examine.ts';
  import { getUser } from '@/api/tplist.ts';
  import { useRouter } from 'vue-router';

  //   import useLoading from '@/hooks/loading';
  //   const { loading, setLoading } = useLoading(true);
  const router = useRouter();
  const mensid = ref('3');
  const eramdata = ref([]);
  const columns = [
    {
      title: '序号',
      dataIndex: 'examineId',
    },
    {
      title: '考核名称',
      dataIndex: 'examineName',
    },
    {
      title: '考核用时',
      dataIndex: 'examineTime',
    },
    {
      title: '状态',
      dataIndex: 'examineStatus',
      slotName: 'examineStatus',
    },
    {
      title: '学生姓名',
      dataIndex: 'studentName',
    },
    {
      title: '正确数量',
      dataIndex: 'correct',
    },
    {
      title: '错误数量',
      dataIndex: 'error',
    },
    {
      title: '详情',
      slotName: 'xq',
      align: 'center',
    },
  ];
  const datas = ref([]);
  const fetchData = () => {
    // 查询学生信息

    getUser().then((res) => {
      if (res.code == 200) {
        console.log('查询学生信息完成', res.data);
        // studentId.value = res.data.studentId;
        const data = {
          pageNum: pagination.current,
          ...pagination,
          examineName: '',
          studentId: res.data.studentId,
        };
        getrecordlist(data).then((res) => {
          if (res.code == 200) {
            datas.value = res.data.list;
            pagination.total = res.data.total;
            pagination.current = res.data.pageNum;
            console.log('查询列表成功', res.data);
          }
        });
      }
    });
  };

  const tipshow = ref(false);
  // 学生id
  const studentId = ref('');
  // 考核id
  const examineId = ref('');
  // 考核记录ID
  const examineRecordId = ref('');
  // 考核时限
  const examineTime = ref('');
  // 定义当前选择考核的图谱
  const medicineAtlasId = ref('');
  // 选择考核信息
  const fieldNames = {
    value: 'medicineAtlasId',
    label: 'medicineAtlasName',
  };
  const options = ref([]);
  const xqfn = (item) => {
    ksshow.value = true;
    examineId.value = item.examineId;
    examineRecordId.value = item.examineRecordId;
    console.log('查询考核详情', item);
    getTp({
      examineId: item.examineId,
    }).then((res) => {
      if (res.code == 200) {
        console.log('查询考核图谱成功', res.data);
        options.value = res.data;
      }
    });
  };

  // 选择考试
  const ksshow = ref(false);
  const changefn = () => {
    tipshow.value = false;
    console.log('当前选择的考核图谱id', medicineAtlasId.value);
  };

  const gostart = () => {
    if (medicineAtlasId.value) {
      router.push({
        name: 'exramxq',
        query: {
          examineId: examineId.value,
          studentId: studentId.value,
          examineRecordId: examineRecordId.value,
          examineTime: examineTime.value,
          medicineAtlasId: medicineAtlasId.value,
        },
      });
    } else {
      tipshow.value = true;
    }
  };
  fetchData();
  const formModel = ref({
    examineName: '',
  });
  // 重置
  const reset = () => {
    formModel.value = {};
    fetchData();
  };
  const basePagination: Pagination = {
    current: 1,
    pageSize: 10,
    total: 0,
  };
  const pagination = reactive({
    ...basePagination,
    'hide-on-single-page': true,
    'show-total': true,
    'show-jumper': true,
    'show-page-size': true,
  });
  const onPageChange = (current: number) => {
    pagination.current = current;
    fetchData();
  };
  const onPageSizeChange = (pageSize: number) => {
    pagination.pageSize = pageSize;
    fetchData();
  };
</script>

<style scoped>
  .sbody {
    background: #f5f6fa !important;
    width: 100%;
    height: 100%;
  }
  .tplistbox {
    display: flex;
    flex-direction: column;
    /* margin: 0 auto; */
    /* margin-top: -150px; */
    position: relative;
    height: auto;
  }
  .bjbox {
    width: 100%;
    height: 172px;
    position: absolute;
    top: 0;
  }
  .bjbox img {
    width: 100%;
    height: 172px;
  }
  .ztnr {
    width: 100%;
    padding: 0 350px;
    z-index: 99;
    margin: 14px auto;
    display: flex;
    flex-wrap: wrap; /* 允许换行 */
    justify-content: space-between; /* 在行中均匀分布 */
  }

  .exramitembox {
    width: calc(50% - 10px); /* 每个盒子占据一半宽度，减去间距 */
    height: 347px;
    background: #f5f6fa;
    box-shadow: 0px 4px 11px 0px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    margin-bottom: 20px; /* 下方间距 */
    display: flex;
    flex-direction: column;
  }
  .exramtop {
    width: 593px;
    height: 140px;
    background: #ffffff;
    border-radius: 4px 4px 0px 0px;
    display: flex;
    flex-direction: column;
    padding: 12px;
  }
  .exrambottom {
    width: 593px;
    height: 207px;
    background: #f5f6fa;
    box-shadow: 0px 4px 11px 0px rgba(0, 0, 0, 0.1);
  }
  .eramnamebox {
    font-size: 18px;
    color: #000000;
    width: 555px;
    font-weight: bold;
    overflow: hidden;
    text-wrap: nowrap;
    text-overflow: ellipsis;
    margin: 15px 0;
  }
  .eramnclass {
    font-size: 16px;
    color: #999999;
  }
  .eramnclass span {
    color: #333333;
  }
  .exramstartbox {
    width: 106px;
    height: 34px;
    background: #0c71ff;
    border-radius: 4px 4px 4px 4px;
    color: #ffffff;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    cursor: pointer;
  }
  .exrambottom {
    display: flex;
    flex-direction: column;
    padding: 0 12px;
  }
  .exramtime {
    margin: 15px 0;
    display: flex;
    justify-content: space-between;
  }
  .exramtimeleft {
    font-size: 16px;
    color: #999999;
  }
  .exramtimeright {
    font-size: 16px;
    color: #333333;
  }
  .tpinputbox {
    display: flex;
  }

  .tpbutton {
    cursor: pointer;
    width: 120px;
    font-size: 18px;
    height: 35px;
    text-align: center;
    line-height: 35px;
    background: #ffffff;
    border-radius: 4px 4px 4px 4px;
    color: #0c71ff;
    margin: 0 10px;
  }
  .tpbuttonnthchild {
    margin-right: 0px;
  }
  .tpmainbox {
    width: 100%;
    height: 723px;
    background: #ffffff;
    border-radius: 4px 4px 4px 4px;
    margin-top: 15px;
    padding: 15px 20px;
  }
  .khztbox {
    width: 48px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    background: rgba(14, 188, 168, 0.2);
    border-radius: 4px 4px 4px 4px;
    color: #0ebca8;
    font-size: 12px;
    margin: 0 auto;
  }
  .khztboxs {
    width: 48px;
    height: 24px;
    text-align: center;
    line-height: 24px;
    font-size: 12px;
    background: rgba(255, 63, 26, 0.2);
    border-radius: 4px 4px 4px 4px;
    color: #ff3f1a;
    margin: 0 auto;
  }
  .khztboxss {
    width: 48px;
    height: 24px;
    line-height: 24px;
    font-size: 12px;
    text-align: center;
    background: #ebebeb;
    border-radius: 4px 4px 4px 4px;
    color: #666666;
    margin: 0 auto;
  }
  .xqbox {
    color: #0c71ff;
    cursor: pointer;
  }
  .tcbox {
    width: 713px;
    height: 229px;
    background: #ffffff;
    border-radius: 0px 0px 0px 0px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 999;
    display: flex;
    flex-direction: column;
  }
  .tctopbox {
    width: 100%;
    height: 46px;
    background: #cfcfcf;
    display: flex;
    align-items: center;
  }
  .tcclose {
    position: absolute;
    right: 10px;
    cursor: pointer;
  }
  .tctopname {
    font-size: 16px;
    color: #000000;
    margin: 0 auto;
  }
  .tcmainbox {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
  }
  .tcmainitem {
    display: flex;
    align-items: center;
    margin: 0 auto;
    border: 1px solid #c1c1c1;
    width: 491px;
    height: 44px;
  }
  .tcitemname {
    width: 175px;
    height: 44px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #c1c1c1;
  }
  .tcitdes {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
  }
  .zzcbox {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    position: absolute;
    top: 0;
    left: 0;
  }
  .startbox {
    width: 112px;
    height: 37px;
    background: linear-gradient(180deg, #ffffff 0%, #c0c0c0 100%);
    border-radius: 4px 4px 4px 4px;
    border: 1px solid #999999;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    cursor: pointer;
    font-size: 16px;
  }
  .tsred {
    color: red;

    position: absolute;
    bottom: 75px;
    left: 50%;
    transform: translate(-50%, 0);
  }
</style>
